/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.FUNCTION.PASSBOOK;

import BUS.SavingBookBUS;
import BUS.Unity;
import GUI.FUNCTION.CUSTOMER.*;
import java.awt.Color;
import java.awt.Image;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wonka
 */
public class FunctionFindPassBook extends org.jdesktop.swingx.JXPanel {
    /**
     * Creates new form Home
     */
    Unity unity=new Unity();
    TablePassBook model_passbook=new TablePassBook();
    SavingBookBUS savingbook_bus=new SavingBookBUS();
    String sql="select FullName,IDNumber,TypeName,Term,InterestRate,AccountBalance,OpeningDate,SBStatus from (customer inner join savingbook on customer.customerid=savingbook.customerid) inner join savingtype on savingtype.typeid=savingbook.typeid";
    public FunctionFindPassBook() throws Exception {
        initComponents();
        model_passbook.SetTable(jXTable1);
        model_passbook.SetData(sql);
        //load data into combobox
        unity.load_combobox(cb_TenLoaiSoTietKiem,"savingtype", "TypeName");
        cb_TrangThaiSTK.addItem("Mở");
        cb_TrangThaiSTK.addItem("Đóng");
    }
    public void ReLoadTable(String sql) throws Exception
    {
        this.sql=sql;
        model_passbook.RemoveData();
        model_passbook.SetData(sql);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXLabel2 = new org.jdesktop.swingx.JXLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jXButton1 = new org.jdesktop.swingx.JXButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        HoTen = new org.jdesktop.swingx.JXTextField();
        CMND = new org.jdesktop.swingx.JXTextField();
        cb_TrangThaiSTK = new org.jdesktop.swingx.JXComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jXButton2 = new org.jdesktop.swingx.JXButton();
        jXButton4 = new org.jdesktop.swingx.JXButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        cb_TenLoaiSoTietKiem = new org.jdesktop.swingx.JXComboBox();
        LaiXuat1 = new org.jdesktop.swingx.JXTextField();
        LaiXuat2 = new org.jdesktop.swingx.JXTextField();
        SoTienGui1 = new org.jdesktop.swingx.JXTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        SoTienGui2 = new org.jdesktop.swingx.JXTextField();
        NgayMo1 = new org.jdesktop.swingx.JXDatePicker();
        NgayMo2 = new org.jdesktop.swingx.JXDatePicker();
        KyHan2 = new org.jdesktop.swingx.JXTextField();
        KyHan1 = new org.jdesktop.swingx.JXTextField();

        setBackground(new java.awt.Color(255, 253, 218));
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setAutoscrolls(true);
        setScrollableHeightHint(org.jdesktop.swingx.ScrollableSizeHint.FIT);
        setScrollableWidthHint(org.jdesktop.swingx.ScrollableSizeHint.FIT);

        jXLabel2.setBackground(new java.awt.Color(153, 255, 255));
        jXLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Medium_FindPassBook.png"))); // NOI18N
        jXLabel2.setText("Tra Cứu Sổ Tiết Kiệm");
        jXLabel2.setFont(new java.awt.Font("Segoe UI Semibold", 1, 18)); // NOI18N

        jXPanel1.setBackground(new java.awt.Color(255, 253, 218));
        jXPanel1.setMinimumSize(new java.awt.Dimension(686, 470));
        jXPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jXButton1.setBackground(new java.awt.Color(255, 255, 51));
        jXButton1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        jXButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Close.png"))); // NOI18N
        jXButton1.setText("Thoát");
        jXButton1.setFocusPainted(false);
        jXButton1.setMaximumSize(new java.awt.Dimension(150, 40));
        jXButton1.setMinimumSize(new java.awt.Dimension(150, 40));
        jXButton1.setPreferredSize(new java.awt.Dimension(130, 40));
        jXPanel1.add(jXButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(798, 127, 150, 31));

        jXTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Mã Sổ", "Mã Khách Hàng", "Ngày Mở Sổ", "Loại Tiết Kiệm", "Kỳ Hạn", "Hình Thức Tính Lãi", "Lãi Suất", "Đơn vị tiền", "Số Tiền Gửi"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.Byte.class, java.lang.String.class, java.lang.Double.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, true, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jXTable1.setToolTipText("");
        jXTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jXTable1);

        jXPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 220, 938, 232));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel1.setText("Họ Tên");
        jXPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 10, -1, -1));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel2.setText("Số CMND");
        jXPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 77, -1, -1));

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel3.setText("Trạng Thái Sổ");
        jXPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 130, -1, -1));

        HoTen.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                HoTenCaretUpdate(evt);
            }
        });
        jXPanel1.add(HoTen, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 0, 106, 32));
        jXPanel1.add(CMND, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 70, 110, 30));
        jXPanel1.add(cb_TrangThaiSTK, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 120, 110, 30));

        jLabel5.setText("Ngày Mở:");
        jXPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(254, 11, -1, -1));

        jLabel6.setText("Số Tiền Gửi");
        jXPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(254, 78, -1, -1));

        jLabel7.setText("Lãi Suất");
        jXPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 130, -1, -1));

        jLabel8.setText("Từ");
        jXPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(329, 11, -1, -1));

        jLabel9.setText("Đến");
        jXPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 10, -1, -1));

        jLabel12.setText("Từ");
        jXPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 130, -1, -1));

        jLabel13.setText("Đến");
        jXPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 130, -1, -1));

        jXButton2.setBackground(new java.awt.Color(255, 255, 51));
        jXButton2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        jXButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Close.png"))); // NOI18N
        jXButton2.setText("Nhập Lại");
        jXButton2.setFocusPainted(false);
        jXButton2.setMaximumSize(new java.awt.Dimension(150, 40));
        jXButton2.setMinimumSize(new java.awt.Dimension(150, 40));
        jXButton2.setPreferredSize(new java.awt.Dimension(130, 40));
        jXPanel1.add(jXButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(798, 0, 150, -1));

        jXButton4.setBackground(new java.awt.Color(255, 255, 51));
        jXButton4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 102, 0)));
        jXButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Small_Close.png"))); // NOI18N
        jXButton4.setText("Cập Nhật");
        jXButton4.setFocusPainted(false);
        jXButton4.setMaximumSize(new java.awt.Dimension(150, 40));
        jXButton4.setMinimumSize(new java.awt.Dimension(150, 40));
        jXButton4.setPreferredSize(new java.awt.Dimension(130, 40));
        jXPanel1.add(jXButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(798, 59, 150, 47));

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel4.setText("Kỳ Hạn");
        jXPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 180, -1, -1));

        jLabel14.setText("Từ");
        jXPanel1.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 180, -1, -1));

        jLabel15.setText("Đến");
        jXPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 180, -1, -1));

        jLabel16.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        jLabel16.setText("Tên Loại Sổ");
        jXPanel1.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 180, -1, -1));
        jXPanel1.add(cb_TenLoaiSoTietKiem, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 170, 106, 30));

        LaiXuat1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LaiXuat1ActionPerformed(evt);
            }
        });
        jXPanel1.add(LaiXuat1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 120, 120, 30));
        jXPanel1.add(LaiXuat2, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 120, 110, 31));

        SoTienGui1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SoTienGui1ActionPerformed(evt);
            }
        });
        jXPanel1.add(SoTienGui1, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 70, 120, 30));

        jLabel17.setText("Từ");
        jXPanel1.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(329, 78, -1, -1));

        jLabel18.setText("Đến");
        jXPanel1.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 80, -1, -1));

        SoTienGui2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SoTienGui2ActionPerformed(evt);
            }
        });
        jXPanel1.add(SoTienGui2, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 70, 110, 31));
        jXPanel1.add(NgayMo1, new org.netbeans.lib.awtextra.AbsoluteConstraints(372, 0, 120, 37));
        jXPanel1.add(NgayMo2, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 0, -1, 37));

        KyHan2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                KyHan2ActionPerformed(evt);
            }
        });
        jXPanel1.add(KyHan2, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 170, 110, 28));

        KyHan1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                KyHan1ActionPerformed(evt);
            }
        });
        jXPanel1.add(KyHan1, new org.netbeans.lib.awtextra.AbsoluteConstraints(372, 171, 120, 28));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 958, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 467, Short.MAX_VALUE)
                .addGap(16, 16, 16))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jXTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable1MouseClicked
        // TODO add your handling code here:
        int index=jXTable1.getSelectedRow();
        for(int i=0;i<jXTable1.getColumnCount();i++)
        {
            if(i==0)
            {
                HoTen.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==1)
            {
                CMND.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==2)
            {
                cb_TenLoaiSoTietKiem.setSelectedItem(jXTable1.getValueAt(index, i));
            }
            if(i==3)
            {
                KyHan1.setText(jXTable1.getValueAt(index, i)+"");
                KyHan2.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==4)
            {
                LaiXuat1.setText(jXTable1.getValueAt(index, i)+"");
                LaiXuat2.setText(jXTable1.getValueAt(index, i)+"");
            }
            if(i==5)
            {
                SoTienGui1.setText(jXTable1.getValueAt(index, i)+"");
                SoTienGui2.setText(jXTable1.getValueAt(index, i)+"");
            }
            
            if(i==6)
            {
                NgayMo1.setDate((Date) jXTable1.getValueAt(index, i));
                NgayMo2.setDate((Date) jXTable1.getValueAt(index, i));
            }
            if(i==7)
            {
                cb_TrangThaiSTK.setSelectedItem(jXTable1.getValueAt(index, i));
            }
        }
    }//GEN-LAST:event_jXTable1MouseClicked

    private void LaiXuat1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LaiXuat1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_LaiXuat1ActionPerformed

    private void SoTienGui1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SoTienGui1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SoTienGui1ActionPerformed

    private void KyHan2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_KyHan2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_KyHan2ActionPerformed

    private void KyHan1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_KyHan1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_KyHan1ActionPerformed

    private void SoTienGui2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SoTienGui2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_SoTienGui2ActionPerformed

    private void HoTenCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_HoTenCaretUpdate
        // TODO add your handling code here:
        try {
            // TODO add your handling code here
            /*
            String sql=savingbook_bus.Search(
                    HoTen.getText()!="",HoTen.getText()!=""?HoTen.getText():"", 
                    CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                    cb_TrangThaiSTK.getSelectedItem()!="",cb_TrangThaiSTK.getSelectedItem()!=""?cb_TrangThaiSTK.getSelectedItem():"", 
                    true, sql, true, sql, sql, true, TOP_ALIGNMENT, TOP_ALIGNMENT, true, TOP_ALIGNMENT, TOP_ALIGNMENT, true, WIDTH, WIDTH)
            String sql=customer_bus.Search(
                    MaKH.getText()!="", MaKH.getText()!=""?MaKH.getText():"", 
                    HoTen.getText()!="", HoTen.getText()!=""?HoTen.getText():"", 
                    CMND.getText()!="", CMND.getText()!=""?CMND.getText():"", 
                    DiaChi.getText()!="", DiaChi.getText()!=""?DiaChi.getText():"", 
                    Email.getText()!="", Email.getText()!=""?Email.getText():"", 
                    SoDienThoai.getText()!="", SoDienThoai.getText()!=""?SoDienThoai.getText():"");
            this.sql=sql;
            ReLoadTable(sql);
            */
        } catch (Exception ex) {
            Logger.getLogger(FunctionFindCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_HoTenCaretUpdate

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXTextField CMND;
    private org.jdesktop.swingx.JXTextField HoTen;
    private org.jdesktop.swingx.JXTextField KyHan1;
    private org.jdesktop.swingx.JXTextField KyHan2;
    private org.jdesktop.swingx.JXTextField LaiXuat1;
    private org.jdesktop.swingx.JXTextField LaiXuat2;
    private org.jdesktop.swingx.JXDatePicker NgayMo1;
    private org.jdesktop.swingx.JXDatePicker NgayMo2;
    private org.jdesktop.swingx.JXTextField SoTienGui1;
    private org.jdesktop.swingx.JXTextField SoTienGui2;
    private org.jdesktop.swingx.JXComboBox cb_TenLoaiSoTietKiem;
    private org.jdesktop.swingx.JXComboBox cb_TrangThaiSTK;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXButton jXButton1;
    private org.jdesktop.swingx.JXButton jXButton2;
    private org.jdesktop.swingx.JXButton jXButton4;
    private org.jdesktop.swingx.JXLabel jXLabel2;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTable jXTable1;
    // End of variables declaration//GEN-END:variables
}
